using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace Medianamik.Core.DAL.SubSonicDAL
{
	/// <summary>
	/// Strongly-typed collection for the SchemaChange class.
	/// </summary>
    [Serializable]
	public partial class SchemaChangeCollection : ActiveList<SchemaChange, SchemaChangeCollection>
	{	   
		public SchemaChangeCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>SchemaChangeCollection</returns>
		public SchemaChangeCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                SchemaChange o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the medianamik_SchemaChange table.
	/// </summary>
	[Serializable]
	public partial class SchemaChange : ActiveRecord<SchemaChange>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public SchemaChange()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public SchemaChange(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public SchemaChange(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public SchemaChange(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("medianamik_SchemaChange", TableType.Table, DataService.GetInstance("MedianamikProvider"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarSchemaChangeId = new TableSchema.TableColumn(schema);
				colvarSchemaChangeId.ColumnName = "SchemaChangeId";
				colvarSchemaChangeId.DataType = DbType.Int32;
				colvarSchemaChangeId.MaxLength = 0;
				colvarSchemaChangeId.AutoIncrement = true;
				colvarSchemaChangeId.IsNullable = false;
				colvarSchemaChangeId.IsPrimaryKey = true;
				colvarSchemaChangeId.IsForeignKey = false;
				colvarSchemaChangeId.IsReadOnly = false;
				colvarSchemaChangeId.DefaultSetting = @"";
				colvarSchemaChangeId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSchemaChangeId);
				
				TableSchema.TableColumn colvarMajorReleaseNumber = new TableSchema.TableColumn(schema);
				colvarMajorReleaseNumber.ColumnName = "MajorReleaseNumber";
				colvarMajorReleaseNumber.DataType = DbType.AnsiString;
				colvarMajorReleaseNumber.MaxLength = 2;
				colvarMajorReleaseNumber.AutoIncrement = false;
				colvarMajorReleaseNumber.IsNullable = false;
				colvarMajorReleaseNumber.IsPrimaryKey = false;
				colvarMajorReleaseNumber.IsForeignKey = false;
				colvarMajorReleaseNumber.IsReadOnly = false;
				colvarMajorReleaseNumber.DefaultSetting = @"";
				colvarMajorReleaseNumber.ForeignKeyTableName = "";
				schema.Columns.Add(colvarMajorReleaseNumber);
				
				TableSchema.TableColumn colvarMinorReleaseNumber = new TableSchema.TableColumn(schema);
				colvarMinorReleaseNumber.ColumnName = "MinorReleaseNumber";
				colvarMinorReleaseNumber.DataType = DbType.AnsiString;
				colvarMinorReleaseNumber.MaxLength = 2;
				colvarMinorReleaseNumber.AutoIncrement = false;
				colvarMinorReleaseNumber.IsNullable = false;
				colvarMinorReleaseNumber.IsPrimaryKey = false;
				colvarMinorReleaseNumber.IsForeignKey = false;
				colvarMinorReleaseNumber.IsReadOnly = false;
				colvarMinorReleaseNumber.DefaultSetting = @"";
				colvarMinorReleaseNumber.ForeignKeyTableName = "";
				schema.Columns.Add(colvarMinorReleaseNumber);
				
				TableSchema.TableColumn colvarPointReleaseNumber = new TableSchema.TableColumn(schema);
				colvarPointReleaseNumber.ColumnName = "PointReleaseNumber";
				colvarPointReleaseNumber.DataType = DbType.AnsiString;
				colvarPointReleaseNumber.MaxLength = 4;
				colvarPointReleaseNumber.AutoIncrement = false;
				colvarPointReleaseNumber.IsNullable = false;
				colvarPointReleaseNumber.IsPrimaryKey = false;
				colvarPointReleaseNumber.IsForeignKey = false;
				colvarPointReleaseNumber.IsReadOnly = false;
				colvarPointReleaseNumber.DefaultSetting = @"";
				colvarPointReleaseNumber.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPointReleaseNumber);
				
				TableSchema.TableColumn colvarScriptName = new TableSchema.TableColumn(schema);
				colvarScriptName.ColumnName = "ScriptName";
				colvarScriptName.DataType = DbType.AnsiString;
				colvarScriptName.MaxLength = 50;
				colvarScriptName.AutoIncrement = false;
				colvarScriptName.IsNullable = false;
				colvarScriptName.IsPrimaryKey = false;
				colvarScriptName.IsForeignKey = false;
				colvarScriptName.IsReadOnly = false;
				colvarScriptName.DefaultSetting = @"";
				colvarScriptName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarScriptName);
				
				TableSchema.TableColumn colvarDateApplied = new TableSchema.TableColumn(schema);
				colvarDateApplied.ColumnName = "DateApplied";
				colvarDateApplied.DataType = DbType.DateTime;
				colvarDateApplied.MaxLength = 0;
				colvarDateApplied.AutoIncrement = false;
				colvarDateApplied.IsNullable = false;
				colvarDateApplied.IsPrimaryKey = false;
				colvarDateApplied.IsForeignKey = false;
				colvarDateApplied.IsReadOnly = false;
				colvarDateApplied.DefaultSetting = @"";
				colvarDateApplied.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateApplied);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["MedianamikProvider"].AddSchema("medianamik_SchemaChange",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("SchemaChangeId")]
		[Bindable(true)]
		public int SchemaChangeId 
		{
			get { return GetColumnValue<int>(Columns.SchemaChangeId); }
			set { SetColumnValue(Columns.SchemaChangeId, value); }
		}
		  
		[XmlAttribute("MajorReleaseNumber")]
		[Bindable(true)]
		public string MajorReleaseNumber 
		{
			get { return GetColumnValue<string>(Columns.MajorReleaseNumber); }
			set { SetColumnValue(Columns.MajorReleaseNumber, value); }
		}
		  
		[XmlAttribute("MinorReleaseNumber")]
		[Bindable(true)]
		public string MinorReleaseNumber 
		{
			get { return GetColumnValue<string>(Columns.MinorReleaseNumber); }
			set { SetColumnValue(Columns.MinorReleaseNumber, value); }
		}
		  
		[XmlAttribute("PointReleaseNumber")]
		[Bindable(true)]
		public string PointReleaseNumber 
		{
			get { return GetColumnValue<string>(Columns.PointReleaseNumber); }
			set { SetColumnValue(Columns.PointReleaseNumber, value); }
		}
		  
		[XmlAttribute("ScriptName")]
		[Bindable(true)]
		public string ScriptName 
		{
			get { return GetColumnValue<string>(Columns.ScriptName); }
			set { SetColumnValue(Columns.ScriptName, value); }
		}
		  
		[XmlAttribute("DateApplied")]
		[Bindable(true)]
		public DateTime DateApplied 
		{
			get { return GetColumnValue<DateTime>(Columns.DateApplied); }
			set { SetColumnValue(Columns.DateApplied, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varMajorReleaseNumber,string varMinorReleaseNumber,string varPointReleaseNumber,string varScriptName,DateTime varDateApplied)
		{
			SchemaChange item = new SchemaChange();
			
			item.MajorReleaseNumber = varMajorReleaseNumber;
			
			item.MinorReleaseNumber = varMinorReleaseNumber;
			
			item.PointReleaseNumber = varPointReleaseNumber;
			
			item.ScriptName = varScriptName;
			
			item.DateApplied = varDateApplied;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varSchemaChangeId,string varMajorReleaseNumber,string varMinorReleaseNumber,string varPointReleaseNumber,string varScriptName,DateTime varDateApplied)
		{
			SchemaChange item = new SchemaChange();
			
				item.SchemaChangeId = varSchemaChangeId;
			
				item.MajorReleaseNumber = varMajorReleaseNumber;
			
				item.MinorReleaseNumber = varMinorReleaseNumber;
			
				item.PointReleaseNumber = varPointReleaseNumber;
			
				item.ScriptName = varScriptName;
			
				item.DateApplied = varDateApplied;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn SchemaChangeIdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn MajorReleaseNumberColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn MinorReleaseNumberColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn PointReleaseNumberColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn ScriptNameColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn DateAppliedColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string SchemaChangeId = @"SchemaChangeId";
			 public static string MajorReleaseNumber = @"MajorReleaseNumber";
			 public static string MinorReleaseNumber = @"MinorReleaseNumber";
			 public static string PointReleaseNumber = @"PointReleaseNumber";
			 public static string ScriptName = @"ScriptName";
			 public static string DateApplied = @"DateApplied";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
